// components/tabbar/tabbar.js
import config from '../../config.js';
import Common from '../../common/common.js';
let common = new Common;

Component({
  properties: {

  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行  
      if (getApp().globalData.defaultShopInfo.userType == 6) {
        console.log(getApp().globalData.defaultShopInfo.userType)
        let tabbarList = this.data.tabbarList;
        tabbarList[1].pagePath = '/pages/rightsMgt/rootEmployees/rootEmployees'
        this.setData({
          tabbarList
        })
      }

      //检测iphonex
      wx.getSystemInfo({
        success: res => {
          let modelmes = res.model;
          if (modelmes.search('iPhone X') != -1) {
            this.setData({
              isIphoneX: true,
            })
          } else {
            this.setData({
              isIphoneX: false,
            })
          }
        }
      })

      //获取当前路径
      console.log(getCurrentPages());
      let page = '/' + getCurrentPages()[0].route
      this.setData({
        active_url: page
      })
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    }
  },
  data: {
    active_url: 'pages/index/index',
    isIphoneX: false,
    tabbarList: config.tabbarList,
    showTabaBar: false
  },
  methods: {
    swichTabbar(e) {
      let routeUrl = e.currentTarget.dataset.url;
      //当前页不跳
      if (this.data.active_url == routeUrl) {
        return false
      }
      if (wx.getStorageSync('token')) {
        /**
         * 页面跳转 权限检查 
         * routeType 跳转方式。
         * **/
        let routeType = 'switchTab';
        let params = "";
        common.routeLink(routeUrl, params, routeType)
      } else {
        wx.showModal({
          title: '提示',
          content: '您尚未登录，登录后才可以进行门店管理操作，是否去登录？',
          success: res => {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/login/index',
              })
            } else {
              return false
            }
          }
        })
        return false
      }
    }
  }
})